#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
//#include "config.h"
#include "ffs.h"
#include "cod.h"
#include "evpath.h"
#include "ev_dfg.h"
#include "util.h"

static EVdfg test_dfg;

int generate_record() {
  return 16;
}
/*
int generate_record(int a) {
  return a;
}

int getConnection(double *cArray) {
  return collectConnection(cArray);
}
*/
int main(int argc, char*argv[]) {
    
    char hostname[50];
    hostname[49] = '\0';
    gethostname(hostname, 49);
    
    CManager cm;
    cm = CManager_create();
    {
    //static cod_extern_entry externs[] =
    //    { {"generate_record", (void *) (long) generate_record},
    //      {"getConnection", (void *) (long) getConnection},
    //      {NULL, NULL}
    //    };
    //static char extern_string[] = "int generate_record(int a);\n\
    //int getConnection(double *cArray);\0\0";
    static cod_extern_entry externs[] =
        { {"generate_record", (void *) (long) generate_record},
          {NULL, NULL}
        };
    static char extern_string[] = "int generate_record();\0\0";
    EVadd_standard_routines(cm, extern_string, externs);
    }

    test_dfg = EVdfg_create(cm);
    //printf("begin to join %s as %s\n", argv[1], hostname);
    EVdfg_join_dfg(test_dfg, hostname, argv[1]);
    //printf("ready?\n");
    EVdfg_ready_wait(test_dfg);
    CMrun_network(cm);
}
